package com.xbongbong.paas.model.impl;

import com.xbongbong.outLink.domain.dao.OutLinkConfigDao;
import com.xbongbong.outLink.domain.entity.OuterLinkConfigEntity;
import com.xbongbong.paas.model.OuterLinkConfigModel;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.paas.toolbox.util.DateUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author long.rao
 * @version v1.0
 * @date 2020/8/10 9:32
 * @since v1.0
 */
@Service("outerLinkConfigModel")
public class OuterLinkConfigModelImpl implements OuterLinkConfigModel {

    @Resource
    private OutLinkConfigDao outLinkConfigDao;

    @Override
    public List<OuterLinkConfigEntity> findEntitys(Map<String, Object> param) throws XbbException {
        return outLinkConfigDao.findEntitys(param);
    }

    @Override
    public Integer insert(OuterLinkConfigEntity entity) {
        long now = DateUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        return outLinkConfigDao.insert(entity);
    }

    @Override
    public Integer update(OuterLinkConfigEntity entity) {
        long now = DateTimeUtil.getInt();
        entity.setUpdateTime(now);
        return outLinkConfigDao.update(entity);
    }

    @Override
    public Long save(OuterLinkConfigEntity entity) throws XbbException {
        if (entity.getId() != null){
            update(entity);
        }else {
            insert(entity);
        }
        return entity.getId();
    }
}
